package biz.ezcom.servlet.filter.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * post方式 tomcat与jetty均正常
 * get方式：
 * 		jetty正常:默认使用UTF-8
 * 		tomcat中文乱码:默认使用ISO8859-1
 */
public class ParameterServlet extends HttpServlet{
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("ParameterServlet.doGet()====================");
		doParameter(request, response);
	}
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("ParameterServlet.doPost()====================");
		doParameter(request, response);
	}
	
	private void doParameter(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		request.setAttribute("username",  username);
		request.setAttribute("password",  password);
		System.out.println("username: " + username);
		System.out.println("password: " + password);
		request.getRequestDispatcher("/WEB-INF/jsp/ParameterServlet.jsp").forward(request, response);
	}
	
}
